package logic

import (
	"context"

	"go-zero-mall/app/admin/cmd/rpc/internal/svc"
	"go-zero-mall/app/admin/cmd/rpc/pd"
	"go-zero-mall/app/admin/model"

	"github.com/jinzhu/copier"
	"github.com/zeromicro/go-zero/core/logx"
)

type MenuListAllLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewMenuListAllLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MenuListAllLogic {
	return &MenuListAllLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *MenuListAllLogic) MenuListAll(in *pd.UmsMenuListAllReq) (*pd.UMsMenuListAllResp, error) {
	rowBuilder := l.svcCtx.UmsMenuModel.RowBuilder()
	d, err := l.svcCtx.UmsMenuModel.FindList(l.ctx, rowBuilder)
	if err != nil && err != model.ErrNotFound {
		return nil, err
	}
	var list []*pd.Menu
	copier.Copy(&list, d)
	return &pd.UMsMenuListAllResp{List: list}, nil
}
